<template>
	<view class="pagebox flex-column">
		<view class="flex1 overflow-y pd30">
			<view class="item flex-row pd20" v-for="(v,i) in obj.list" :key="i" @click="goroom(v)">
				<view class="spot flex-center" v-if="v.cou>0">{{v.cou}}</view>
				<view class="headbox">
					<image :src="v.head?`${proxy.$c.fileHost}head/${v.head}`:`../../static/34.png`" mode=""></image>
				</view>
				<view class="w100 flex-column">
					<view class="w100 flex-row-center ju-between mb10">
						<text class="username">询盘客户：{{v.nickname||`客户${i+1}`}}</text>
						<text class="intime">{{v.updatetime||''}}</text>
					</view>
					<view class="title">{{v.title||''}}</view>
				</view>
			</view>
			<view v-if="!obj.list.length" class="nodata flex-center">--暂无历史记录--</view>
		</view>
	</view>
</template>

<script setup>
    import { reactive, getCurrentInstance,onMounted,watch,computed,nextTick } from 'vue'
	import { onLoad,onShow,onTabItemTap,onReachBottom,onPullDownRefresh,onPageScroll,onUnload } from '@dcloudio/uni-app';
    let { proxy } = getCurrentInstance()
	let obj = reactive({
		u: proxy.$c.getUser()?JSON.parse(proxy.$c.getUser()):{},
		req: {
		  "currentpage": 1,
		  "pagesize": 10000
		},
		list: [{}],
	})
	
	onShow(()=>{
		getlist()
	})
	
	onUnload(()=>{
	})
	
	const getlist=()=>{
		proxy.$reQuest.post('customerservice/product/inquiry/service',obj.req,{token:true}).then(res=>{
			if(res.success){
				obj.list = res.msg.list||[]
			}
		}).catch(err=>{})
	}
	
	const goroom=(v)=>{
		proxy.$reQuest.post('customerservice/product/inquiry/room/in',{userid: v.userid,room_id:v.room_id},{token:true}).then(res=>{
			if(res.success){
				proxy.$c.go_url(`/pages/customer/chat${proxy.$c.JSONToUrl({
					...v,
					identity: 'cs'
				})}`)
			}else{
				proxy.$c.Toast(res.err||'回复失败！')
			}
		}).catch(err=>{
			proxy.$c.Toast('回复失败！')
		})
	}
</script>

<style lang="scss" scoped>
	.pagebox{
		width: 100vw;height: 100vh;overflow: hidden;
		background: #f0f0f0;
		.nodata{width: 100%;height: 100%;font-size: 22rpx;color: #999;}
		.item{
			position: relative;
			width: 100%;height: auto;border-radius: 10rpx;background: #fff;margin-bottom: 30rpx;
			.spot{position: absolute;left: 90rpx;top: 20rpx;z-index: 1;width: 10rpx;height: 10rpx;padding: 10rpx;border-radius: 50%;background-color: red;color: #fff;font-size: 22rpx;}
			.headbox{min-width: 100rpx;height: 100rpx;border-radius: 100rpx; overflow: hidden; margin-right: 20rpx; image{width: 100rpx;height: 100rpx;}}
			.title{font-size: 32rpx;font-weight: bold;}
			.username{font-size: 26rpx;color: #333;}
			.intime{font-size: 24rpx;color: #999;}
		}
	}
</style>
